'use strict';
const crypto = require('crypto');

module.exports = (app) => {
  class WebController extends app.Controller {
    async empty(ctx, next) {
      ctx.body = null;
    }

    async staticPage(ctx, next) {
      const { pageId } = ctx.params;
      try {
        const page = await ctx.api.bind.getStaticPage(pageId);
        console.log('page', page);
        ctx.body = page;
      } catch (error) {
        ctx.body = '';
      }
    }

    async staticAssets(ctx, next) {
      console.log('access static files', ctx.href);
      return ctx.staticAssets(ctx, next);
    }

    async notBound(ctx, next) {
      const patientId = await ctx.api.bind.getBindPatientByWeixin(
        ctx.weixin.openId
      );
      if (patientId) {
        ctx.redirect(ctx.query.r || '/user/info');
      }
      ctx.body = await ctx.indexPage('', {
        mount: {
          notBound: {
            redirectUrl: ctx.query.r,
          },
        },
      });
    }

    async addressList(ctx, next) {
      const patientId = await ctx.api.bind.getBindPatientByWeixin(
        ctx.weixin.openId
      );
      if (!patientId) {
        ctx.redirect(`/user/bind?r=${encodeURIComponent('/addressList')}`);
        return;
      }
      ctx.body = await ctx.indexPage('', {
        mount: {
          addressList: {},
        },
      });
    }

    async userBind(ctx, next) {
      const patientId = await ctx.api.bind.getBindPatientByWeixin(
        ctx.weixin.openId
      );
      if (patientId) {
        ctx.redirect(ctx.query.r || '/user/info');
      }
      const { mobile } = ctx.query;
      ctx.body = await ctx.indexPage('绑定', {
        mount: {
          userBind: {
            disabledBind: true,
            disabledGetCapchar: true,
            redirectUrl: ctx.query.r,
            phone: mobile,
          },
        },
      });
    }

    async userBindDemo(ctx, next) {
      // const patientId = await ctx.api.bind.getBindPatientByWeixin(
      //   ctx.weixin.openId
      // );
      // if (patientId) {
      //   ctx.redirect('/medicineHomePageDemo');
      // }
      const { mobile } = ctx.query;
      
      ctx.body = await ctx.indexPage('绑定', {
        mount: {
          userBind: {
            disabledBind: true,
            disabledGetCapchar: true,
            redirectUrl: ctx.query.r,
            phone: mobile,
          },
        },
      });
    }
    async demo(ctx, next) {
      // const patientId = await ctx.api.bind.getBindPatientByWeixin(
      //   ctx.weixin.openId
      // );
      // if (patientId) {
      //   ctx.redirect('/medicineHomePageDemo');
      // }
      
      ctx.body = await ctx.indexPage('绑定', {
        mount: {
        },
      });
    }
    async userMemberType(ctx, next) {
      const { mobilePhone } = ctx.query;
      // if (!mobilePhone) {
      //     ctx.redirect(ctx.query.r || '/user/register');
      // }
      ctx.body = await ctx.indexPage('会员类型', {
        mount: {
          memberType: {
            disabledBind: true,
            disabledGetCapchar: true,
            redirectUrl: ctx.query.r,
            phone: mobilePhone,
          },
        },
      });
    }

    async requirementList(ctx, next) {
      const patientId = ctx.query.patientId
      if (!patientId) {
        ctx.redirect(`/user/bindDemo?r=${encodeURIComponent('/requirementListDemo')}`);
        return;
      }
      ctx.body = await ctx.indexPage('需求单', {
        mount: {
          requirementList: {
            patientId,
          },
        },
      });
    }

    async requirementListUseNum(ctx, next) {
      const patientId = await ctx.api.bind.getBindPatientByWeixin(
        ctx.weixin.openId
      );
      if (!patientId) {
        ctx.redirect(
          `/user/bind?r=${encodeURIComponent('/requirementListUseNum')}`
        );
        return;
      }
      ctx.body = await ctx.indexPage('用法用量', {
        mount: {
          requirementListUseNum: {
            patientId,
            list: ctx.query.list,
          },
        },
      });
    }

    async check(ctx, next) {
      const patientId = ctx.query.patientId
      ctx.body = await ctx.indexPage('结算单', {
        mount: {
          check: {
            patientId,
            page: ctx.query.page,
            commonList: ctx.query.list || [],
          },
        },
      });
    }
    async userInfo(ctx, next) {
      const patientId = await ctx.api.bind.getBindPatientByWeixin(
        ctx.weixin.openId
      );
      if (!patientId) {
        ctx.redirect(`/user/bind?r=${encodeURIComponent('/user/info')}`);
        return;
      }
      const r = await ctx.api.portal.getPatientInfo(patientId);
      if (r && r.patientType == 1) {
        ctx.body = await ctx.indexPage('会员信息', {
          mount: {
            userInfo: r,
          },
        });
      } else {
        ctx.redirect(`/notComplete?r=${encodeURIComponent('/user/info')}`);
      }
    }

    async selfOrder(ctx, next) {
      const patientId = await ctx.api.bind.getBindPatientByWeixin(
        ctx.weixin.openId
      );
      if (!patientId) {
        ctx.redirect(`/user/bind?r=${encodeURIComponent('/selforder')}`);
        return;
      }
      const patient = await ctx.api.portal.getPatientInfo(patientId);
      if (patient && patient.patientType == 1) {
        try {
          const r = await ctx.api.portal.getDefaultDrugs(patientId);
          if (r.drugs.length) {
            r.drugs.forEach((drug) => {
              if (!drug.amount) {
                drug.amount = 1;
              }
            });
          }
          ctx.body = await ctx.indexPage('续订', {
            mount: {
              selfOrder: {
                patientId,
                hospitalId: patient.hospital.id,
                defaultDrugs: r,
              },
            },
          });
        } catch (e) {
          ctx.throwMessage('暂不支持续订，请前往签约机构订药');
        }
      } else {
        ctx.redirect(`/notComplete?r=${encodeURIComponent('/selforder')}`);
      }
    }

    async orderDetail(ctx, next) {
      try {
        const orderId = ctx.params.orderId;
        const patientId = await ctx.api.bind.getBindPatientByWeixin(
          ctx.weixin.openId
        );
        if (!patientId) {
          ctx.redirect(
            `/user/bind?r=${encodeURIComponent(`/order/${orderId}`)}`
          );
          return;
        }
        const r = await ctx.api.portal.getOrderDetail(patientId, orderId);
        const orderLogs = await ctx.api.portal.getOrderLogs(orderId);
        const expressFlowList = await ctx.api.portal.getOrderExpressFlowList(
          orderId
        );
        const returnDetail = await ctx.api.portal.getReturnDetail(orderId);
        ctx.body = await ctx.indexPage('订单详情', {
          mount: {
            orderDetail: {
              orderId,
              order: r,
              orderLogs: orderLogs,
              returnDetail,
              expressFlowList,
            },
          },
        });
      } catch (e) {
        if (e.code !== 239) {
          throw e;
        }
        ctx.throwMessage('无法查看其他会员的订单');
      }
    }

    async orderDetailDemo(ctx, next) {
      try {
        const orderId = ctx.params.orderId;
        const patientId = ctx.query.patientId
        if (!patientId) {
          ctx.redirect(
            `/user/bindDemo?r=${encodeURIComponent(`/orderDemo/${orderId}`)}`
          );
          return;
        }
        const r = await ctx.api.portal.getOrderDetail(patientId, orderId);
        const orderLogs = await ctx.api.portal.getOrderLogs(orderId);
        const expressFlowList = await ctx.api.portal.getOrderExpressFlowList(
          orderId
        );
        const returnDetail = await ctx.api.portal.getReturnDetail(orderId);
        ctx.body = await ctx.indexPage('订单详情', {
          mount: {
            orderDetail: {
              orderId,
              order: r,
              orderLogs: orderLogs,
              returnDetail,
              expressFlowList,
            },
          },
        });
      } catch (e) {
        if (e.code !== 239) {
          throw e;
        }
        ctx.throwMessage('无法查看其他会员的订单');
      }
    }

    async returnDetail(ctx, next) {
      try {
        const { orderId } = ctx.params;
        const patientId = await ctx.api.bind.getBindPatientByWeixin(
          ctx.weixin.openId
        );
        if (!patientId) {
          ctx.redirect(
            `/user/bind?r=${encodeURIComponent(`/order/${orderId}`)}`
          );
          return;
        }
        const r = await ctx.api.portal.getReturnDetail(orderId);
        // const r = await ctx.api.portal.getOrderDetail(patientId, orderId);
        ctx.body = await ctx.indexPage('订单详情', {
          mount: {
            returnDetail: {
              orderId,
              returnDetail: r,
            },
          },
        });
      } catch (e) {
        if (e.code !== 239) {
          throw e;
        }
        ctx.throwMessage('无法查看其他会员的订单');
      }
    }

    async druglist(ctx, next) {
      const patientId = await ctx.api.bind.getBindPatientByWeixin(
        ctx.weixin.openId
      );
      const data = {
        drugList: [],
        noMoreDrugTip: false,
        hospital: {},
      };
      if (patientId) {
        const patient = await ctx.api.portal.getPatientInfo(patientId);
        data.hospital = patient.hospital;
      }
      ctx.body = await ctx.indexPage('药品目录', {
        mount: {
          druglist: data,
        },
      });
    }

    async drugDetail(ctx, next) {
      ctx.body = await ctx.indexPage('药品详情', {
        mount: {
          drugDetail: {},
        },
      });
    }

    async hospitals(ctx, next) {
      const wx = await ctx.api.bind.getWeixinInfo(app.config.weixin.appId);

      ctx.body = await ctx.indexPage('服务网点', {
        mount: {
          serverNet: {
            weixinLabel: wx.label,
          },
        },
      });
    }

    async sendDrug(ctx, next) {
      ctx.body = await ctx.indexPage('发药', {
        mount: {
          sendDrug: {
            baseUrl: app.config.pbm.baseUrl,
          },
        },
      });
    }

    async sendDrugLogin(ctx, next) {
      ctx.body = await ctx.indexPage('登录', {
        mount: {
          sendDrug: {
            baseUrl: app.config.pbm.baseUrl,
          },
        },
      });
    }

    async sendDrugDetails(ctx, next) {
      ctx.body = await ctx.indexPage('包裹信息', {
        mount: {
          sendDrug: {
            baseUrl: app.config.pbm.baseUrl,
          },
        },
      });
    }

    async patientService(ctx, next) {
      ctx.body = await ctx.indexPage('患者服务', {
        mount: {
          patientService: {},
        },
      });
    }
    async patientDetails(ctx, next) {
      ctx.body = await ctx.indexPage('患者详情', {
        mount: {
          patientDetails: {},
        },
      });
    }

    async record(ctx, next) {
      try {
        const patientId = await ctx.api.bind.getBindPatientByWeixin(
          ctx.weixin.openId
        );
        if (!patientId) {
          ctx.redirect(`/user/bind?r=${encodeURIComponent('/record')}`);
          return;
        }
        const patient = await ctx.api.portal.getPatientInfo(patientId);
        if (patient && patient.patientType == 1) {
          await ctx.indexPage('预定记录', {
            mount: {
              record: {
                patientId,
              },
            },
          });
        } else {
          ctx.redirect(`/notComplete?r=${encodeURIComponent('/record')}`);
          return;
        }
      } catch (e) {
        throw e;
        ctx.throwMessage('查看预定记录失败！');
      }
    }

    async orderSchedule(ctx, next) {
      try {
        const patientId = await ctx.api.bind.getBindPatientByWeixin(
          ctx.weixin.openId
        );
        const orderId = ctx.params.orderId;
        const orderInfo = await ctx.api.portal.getOrderDetail(
          patientId,
          orderId
        );
        const orderLogs = await ctx.api.portal.getOrderLogs(orderId);
        await ctx.indexPage('订单进度', {
          mount: {
            orderSchedule: {
              orderLogs,
              orderInfo,
            },
          },
        });
      } catch (e) {
        throw e;
        ctx.throwMessage('查看订单日志失败！');
      }
    }

    async cancelReason(ctx, next) {
      try {
        const cancelReasonList = await ctx.api.portal.getOrderCancelReason();
        const orderId = ctx.params.orderId;
        const patientId = await ctx.api.bind.getBindPatientByWeixin(
          ctx.weixin.openId
        );
        const patient = await ctx.api.portal.getPatientInfo(patientId);
        let patientName = (patient && patient.name) || '';
        await ctx.indexPage('取消订药', {
          mount: {
            cancelReason: {
              cancelReasonList,
              orderId,
              patientName,
            },
          },
        });
      } catch (e) {
        throw e;
        // ctx.throwMessage('获取取消原因失败！');
      }
    }

    async potentialPatients(ctx, next) {
      ctx.body = await ctx.indexPage('万户PBM·太原市医改惠民项目', {
        mount: {
          serverNet: {},
        },
      });
    }

    async register(ctx, next) {
      const patientId = await ctx.api.bind.getBindPatientByWeixin(
        ctx.weixin.openId
      );
      if (patientId) {
        ctx.redirect(ctx.query.r || '/user/info');
      }
      const user = await ctx.api.bind.getWeixinUserInfo(ctx.weixin.openId);
      const { mobile } = ctx.query;
      ctx.body = await ctx.indexPage('微信签约', {
        mount: {
          register: {
            phone: mobile,
            recommendBusinessCode: user ? user.recommendBusinessCode : null,
          },
        },
      });
    }

    async improveInformation(ctx, next) {
      const patientId = await ctx.api.bind.getBindPatientByWeixin(
        ctx.weixin.openId
      );
      if (!patientId) {
        ctx.redirect(`/user/bind?r=${encodeURIComponent('/user/info')}`);
        return;
      }
      const r = await ctx.api.portal.getPatientInfo(patientId);
      if (r.diseases) {
        r.diseases = r.diseases.map((item) => item.id);
      }
      ctx.body = await ctx.indexPage('会员信息', {
        mount: {
          improveInformation: { ...r, patientId, patientAddress: r.address },
        },
      });
    }

    async newAndCourteous(ctx, next) {
      const patientId = await ctx.api.bind.getBindPatientByWeixin(
        ctx.weixin.openId
      );
      if (!patientId) {
        ctx.redirect(`/user/bind?r=${encodeURIComponent(`/newAndCourteous`)}`);
        return;
      }
      const patient = await ctx.api.portal.getPatientInfo(patientId);
      if (patient && patient.patientType == 1) {
        ctx.body = await ctx.indexPage('拉新有礼', {
          mount: {
            newAndCourteous: {
              ...patient,
              patientId,
            },
          },
        });
      } else {
        ctx.redirect(
          `/notComplete?r=${encodeURIComponent('/newAndCourteous')}`
        );
      }
    }

    async newAndShare(ctx, next) {
      let webUrl = app.config.weixin.webUrl;
      ctx.body = await ctx.indexPage('PBM福利计划', {
        mount: {
          newAndShare: {
            patientId: ctx.params,
            webUrl: webUrl,
          },
        },
      });
    }

    async notComplete(ctx) {
      ctx.body = await ctx.indexPage('', {
        mount: {
          serverNet: {},
        },
      });
    }

    // 找药
    async newDrugSearch(ctx) {
      ctx.body = await ctx.indexPage('找药', {
        mount: {
          newDrugSearch: {},
        },
      });
    }

    // 药品详情
    async newDrugDetail(ctx) {
      let data = {};
      const patientId = ctx.query.patientId
      if (patientId) {
        data = {
          drugId: ctx.query.id,
          isSale: ctx.query.page,
          hospitalId: ctx.query.hospitalId,
          patientId: patientId,
        };
      } else {
        data = {
          drugId: ctx.query.id,
          isSale: ctx.query.page,
          hospitalId: ctx.query.hospitalId,
          patientId: '不存在',
        };
      }
      ctx.body = await ctx.indexPage('', {
        mount: {
          newDrugDetail: {
            ...data,
          },
        },
      });
    }

    // 找药首页
    async medicineHomePage(ctx) {
      const patientId = await ctx.api.bind.getBindPatientByWeixin(
        ctx.weixin.openId
      );
      let patientInfo = null;
      if (patientId) {
        patientInfo = await ctx.api.portal.getPatientInfo(patientId);
      }
      ctx.body = await ctx.indexPage('', {
        mount: {
          medicineHomePage: {
            patientId,
            patientInfo,
          },
        },
      });
    }

    // 找药首页Demo
    async medicineHomePageDemo(ctx) {
      const patientId = ctx.query.patientId
      let patientInfo = null;
      if (patientId) {
        patientInfo = await ctx.api.portal.getPatientInfo(patientId);
      }
      ctx.body = await ctx.indexPage('', {
        mount: {
          medicineHomePage: {
            patientId,
            patientInfo,
          },
        },
      });
    }

    async checkSuccess(ctx) {
      const { orderId, orderNo } = ctx.query;
      ctx.body = await ctx.indexPage('预定成功', {
        mount: {
          checkSuccess: {
            orderId,
            orderNo,
          },
        },
      });
    }

    async points(ctx, next) {
      const patientId = await ctx.api.bind.getBindPatientByWeixin(
        ctx.weixin.openId
      );
      if (!patientId) {
        ctx.redirect(`/user/bind?r=${encodeURIComponent('/points')}`);
        return;
      }
      ctx.body = await ctx.indexPage('会员积分', {
        mount: {
          points: {
            patientId,
          },
        },
      });
    }

    async newUserInfo(ctx) {
      const patientId = await ctx.api.bind.getBindPatientByWeixin(
        ctx.weixin.openId
      );
      if (!patientId) {
        ctx.redirect(`/user/bind?r=${encodeURIComponent('/user/info')}`);
        return;
      }
      ctx.body = await ctx.indexPage('', {
        mount: {
          newUserInfo: {},
        },
      });
    }

    async newOrderList(ctx) {
      ctx.body = await ctx.indexPage('', {
        mount: {
          newOrderList: {},
        },
      });
    }

    async newOrderDetail(ctx) {
      const patientId = await ctx.api.bind.getBindPatientByWeixin(
        ctx.weixin.openId
      );
      if (!patientId) {
        ctx.redirect(`/user/bind?r=${encodeURIComponent('/user/info')}`);
        return;
      }
      ctx.body = await ctx.indexPage('', {
        mount: {
          newOrderDetail: {},
        },
      });
    }

    async newUserMember(ctx) {
      const patientId = await ctx.api.bind.getBindPatientByWeixin(
        ctx.weixin.openId
      );
      if (!patientId) {
        ctx.redirect(`/user/bind?r=${encodeURIComponent('/user/info')}`);
        return;
      }
      // const userInfo = await ctx.api.portal.getPatientInfo(patientId);
      ctx.body = await ctx.indexPage('', {
        mount: {
          newUserMember: {
            patientId,
          },
        },
      });
    }

    async orderCommonList(ctx) {
      ctx.body = await ctx.indexPage('', {
        mount: {
          orderCommonList: {
            page: ctx.query.page,
            list: ctx.query.list || [],
            currentList: ctx.query.currentList,
          },
        },
      });
    }

    async vipDay(ctx) {
      const patientId = ctx.api.bind.getBindPatientByWeixin(ctx.weixin.openId);
      if (!patientId) {
        ctx.redirect(`/user/bind?r=${encodeURIComponent('/user/info')}`);
        return;
      }
      ctx.body = await ctx.indexPage('', {
        mount: {
          newVipDay: {
            patientId,
          },
        },
      });
    }

    // 优惠券活动
    async newCoupon(ctx) {
      const patientId = await ctx.api.bind.getBindPatientByWeixin(
        ctx.weixin.openId
      );
      if (!patientId) {
        ctx.redirect(`/user/bind?r=${encodeURIComponent('/user/info')}`);
        return;
      }
      ctx.body = await ctx.indexPage('', {
        mount: {
          newCoupon: {},
        },
      });
    }

    async insuranceRoute(ctx) {
      ctx.body = await ctx.indexPage('保险登记', {
        mount: {
          insuranceRoute: {},
        },
      });
    }
    async getNotice(ctx) {
      ctx.body = await ctx.indexPage('保险协议', {
        mount: {
          insuranceRoute: {},
        },
      });
    }
    //保险登记
    async insurance(ctx) {
      ctx.body = await ctx.indexPage('保险登记', {
        mount: {
          insurance: {},
        },
      });
    }
    //保险支付成功
    async insurancePaySuccess(ctx) {
      ctx.body = await ctx.indexPage('保险支付成功', {
        mount: {
          insurance: {},
        },
      });
    }

    //保障服务方案
    async insuranceServicePlan(ctx) {
      ctx.body = await ctx.indexPage('保障服务方案', {
        mount: {
          insurance: {},
        },
      });
    }

    // 健康首页
    async newHealthHomePage(ctx) {
      ctx.body = await ctx.indexPage('', {
        mount: {
          newHealthHomePage: {},
        },
      });
    }
    // 购药凭证
    async newMedicineCredentials(ctx) {
      ctx.body = await ctx.indexPage('', {
        mount: {
          newMedicineCredentials: {},
        },
      });
    }

    /* 积分规则 */
    async pointRule(ctx) {
      ctx.body = await ctx.indexPage('', {
        mount: {
          pointRule: {},
        },
      });
    }
    /* 怎么使用积分 */
    async howToUsePoint(ctx) {
      ctx.body = await ctx.indexPage('', {
        mount: {
          howToUsePoint: {},
        },
      });
    }
    /* 分享万户宝 */
    async sharePage(ctx) {
      ctx.body = await ctx.indexPage('', {
        mount: {
          sharePage: {},
        },
      });
    }
    /* 分享出去的页面 */
    async shareToOther(ctx) {
      ctx.body = await ctx.indexPage('', {
        mount: {
          shareToOther: {},
        },
      });
    }

    /* 保险订单列表 */
    async insuranceList(ctx) {
      ctx.body = await ctx.indexPage('', {
        mount: {
          insuranceList: {},
        },
      });
    }
    /* 保障列表 */
    async ensureList(ctx) {
      ctx.body = await ctx.indexPage('', {
        mount: {
          ensureList: {},
        },
      });
    }
    /* 保险订单详情 */
    async insuranceInfo(ctx) {
      ctx.body = await ctx.indexPage('', {
        mount: {
          insuranceInfo: {},
        },
      });
    }
    /* BMI */
    async newBMI(ctx) {
      ctx.body = await ctx.indexPage('', {
        mount: {
          newBMI: {},
        },
      });
    }

    async exchangeList(ctx) {
      ctx.body = await ctx.indexPage('', {
        mount: {
          exchangeList: {},
        },
      });
    }

    async exchangeInfo(ctx) {
      ctx.body = await ctx.indexPage('', {
        mount: {
          exchangeInfo: {},
        },
      });
    }

    /**
     * 集福气
     */
    async gatherHappiness(ctx) {
      const user = await ctx.api.bind.getWeixinUserInfo(ctx.weixin.openId);
      ctx.body = await ctx.indexPage('', {
        mount: {
          gatherHappiness: {
            weixinUser: user,
          },
        },
      });
    }

    /* 城市选择 */
    async addressSelect(ctx) {
      ctx.body = await ctx.indexPage('', {
        mount: {
          addressSelect: {},
        },
      });
    }

    async adsVedio(ctx) {
      ctx.body = await ctx.indexPage('', {
        mount: {
          addressSelect: {},
        },
      });
    }

    async defaultPage(ctx) {
      ctx.body = await ctx.indexPage('', {
        mount: {
          defaultPage: {},
        },
      });
    }

    /* 用药评估 */
    async drugEvaluation(ctx) {
      ctx.body = await ctx.indexPage('', {
        mount: {
          drugEvaluation: {},
        },
      });
    }
    /* 参评人员 */
    async evaluationPatient(ctx) {
      ctx.body = await ctx.indexPage('', {
        mount: {
          evaluationPatient: {},
        },
      });
    }
    /* 参评药品信息 */
    async evaluationDrugInfo(ctx) {
      ctx.body = await ctx.indexPage('', {
        mount: {
          evaluationDrugInfo: {},
        },
      });
    }
    /* 参评结果 */
    async evaluationResult(ctx) {
      ctx.body = await ctx.indexPage('', {
        mount: {
          evaluationResult: {},
        },
      });
    }
    async evaluationSearchDrug(ctx) {
      ctx.body = await ctx.indexPage('', {
        mount: {
          evaluationSearchDrug: {},
        },
      });
    }
    /* 健康课堂 */
    async healthClass(ctx) {
      ctx.body = await ctx.indexPage('', {
        mount: {
          healthClass: {},
        },
      });
    }

    /* 健康报 */
    async healthNewsPage(ctx) {
      ctx.body = await ctx.indexPage('', {
        mount: {
          healthNewsPage: {},
        },
      });
    }

    /* 体检 */
    async healthPhysical(ctx) {
      ctx.body = await ctx.indexPage('', {
        mount: {
          healthPhysical: {},
        },
      });
    }

    async toBaiji(ctx) {
      const patientId = await ctx.api.bind.getBindPatientByWeixin(
        ctx.weixin.openId
      );
      if (!patientId) {
        ctx.redirect(`/user/bind?r=${encodeURIComponent('/toBaiji')}`);
        return;
      }
      const info = await ctx.api.portal.getPatientInfo(patientId);
      const { phone } = info;
      const dt = new Date().getTime();
      const content = `wh${patientId}${phone}${dt}`;
      const md5 = crypto.createHash('md5');
      const signinfo = md5.update(content).digest('hex');
      const formData = {
        userid: patientId,
        phone,
        signinfo,
        dt,
      };
      ctx.body = await ctx.indexPage('', {
        mount: {
          baiji: {
            formData,
          },
        },
      });
    }

    async myMedicalReport(ctx) {
      ctx.body = await ctx.indexPage('', {
        mount: {
          myMedicalReport: {},
        },
      });
    }

    async myReportInfo(ctx) {
      ctx.body = await ctx.indexPage('', {
        mount: {
          myReportInfo: {},
        },
      });
    }

    async myDoctor(ctx) {
      ctx.body = await ctx.indexPage('', {
        mount: {
          myDoctor: {},
        },
      });
    }

    async anxinInsurance(ctx) {
      ctx.body = await ctx.indexPage('', {
        mount: {
          anxinInsurance: {},
        },
      });
    }
    /* 保险包列表 */
    async InsuranceBuy(ctx) {
      ctx.body = await ctx.indexPage('', {
        mount: {
          InsuranceBuy: {},
        },
      });
    }
    /*进入视频医生页面*/
    async DoctorGo(ctx) {
      ctx.body = await ctx.indexPage('', {
        mount: {
          DoctorGo: {},
        },
      });
    }
    /*依山工程表单*/
    async YSGC(ctx) {
      ctx.body = await ctx.indexPage('', {
        mount: {
          YSGC: {},
        },
      });
    }
    /*众惠防癌版问询*/
    async zhonghuiCancer(ctx) {
      ctx.body = await ctx.indexPage('', {
        mount: {
          zhonghuiCancer: {},
        },
      });
    }
    async doctorList(ctx) {
      ctx.body = await ctx.indexPage('', {
        mount: {
          doctorList: {},
        },
      });
    }
    async doctorListDetail(ctx) {
      ctx.body = await ctx.indexPage('', {
        mount: {
          doctorListDetail: {},
        },
      });
    }
    async reportList(ctx) {
      ctx.body = await ctx.indexPage('', {
        mount: {
          reportList: {},
        },
      });
    }
    async reportProductions(ctx) {
      ctx.body = await ctx.indexPage('', {
        mount: {
          reportProductions: {},
        },
      });
    }
  }
  return WebController;
};
